create or replace function deletePosterminalProducer(
	out xml, inout xml
	)
as
$$
	declare
		-- alias is name for stored procedure parameters
		executeStatusData 			alias for $1;
		posterminalProducerData		alias for $2;
		
		-- variable for node data
		vIdPosterminalProducer 		bigint := null; -- posterminal producer id in database
		vNameProducer				text := null; 	-- posterminal producer name
		
		-- node path
		vIdNode						varchar(100) := '/posterminalproducer/@id';
	begin
		-- get data from xml
		vIdPosterminalProducer := cast(extract_value(vIdNode, posterminalProducerData) as int);
		
		-- first insert into trace table previous data
		insert into posterminalProducerTrace(idPosterminalProducer, namePosterminalProducer)
			select idPosterminalProducer, namePosterminalProducer from PosterminalProducer poer
				where
					poer.idPosterminalProducer = vIdPosterminalProducer
		;
		-- second delete row from original table
		delete from PosterminalProducer poer
			where
				poer.idPosterminalProducer = vIdPosterminalProducer;
		executeStatusData := statusCall(successcode(), deleteText());
	end;
$$ language plpgsql VOLATILE;